package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    // 根据用户id和菜品或套餐id查询购物车数据
    ShoppingCart selectBy(ShoppingCart shoppingCart);
    // 插入数据,新增购物车
    @Insert("insert into shopping_cart (name,image,dish_id,setmeal_id,dish_flavor,number,amount,create_time,user_id) values (#{name},#{image},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime},#{userId})")
    void insert(ShoppingCart shoppingCart);
    // 根据用户id查询购物车数据
    @Update("update shopping_cart set number = #{number},amount = #{amount} where id = #{id}")
    void update(ShoppingCart cart);
    // 查询当前用户的购物车数据
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);
    // 删除购物车数据
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void delete(Long userId);
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteById(Long id);

    void insertBatch(List<ShoppingCart> shoppingCartList);
}
